package com.productinfo.controller;


import com.code.domain.AjaxResult;
import com.productinfo.entity.Productinfo;
import com.productinfo.entity.Vo.ProductInfoVo;
import com.productinfo.service.IProductinfoService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author guanfenga@yonyou.com
 * @since 2023-02-10
 */
@ApiOperation(value = "商品模块", notes = "商品模块")
@Controller // 相当于控制层类上加@Controller + 方法上加 @ResponseBody
@Slf4j
@CrossOrigin
@RequestMapping("/productinfo")
public class ProductinfoController {

    @Autowired
    private IProductinfoService productinfoService;

    @ApiOperation(value = "查询所有商品", notes = "查询所有商品")
    @PostMapping("/queryProductInfoAll")
    public @ResponseBody AjaxResult queryProductInfoAll(HttpServletRequest request, HttpServletResponse response) {
        List<ProductInfoVo> productinfos = productinfoService.queryProductInfoAll();
        log.info("==========> lianxi");
        return AjaxResult.success("操作成功", productinfos);
    }
    @ApiOperation(value = "根据主键id查询",notes = "根据主键id查询")
    @GetMapping(value = "/queryProductInfoById/{productId}")
    public @ResponseBody AjaxResult queryProductInfoById(@PathVariable String productId){
        Productinfo productInfo = productinfoService.queryProductInfoById(productId);
        return AjaxResult.success("操作成功",productInfo);
    }
}
